package com.zengqingfa.designpattern.behavior.observer.guava;

import com.google.common.eventbus.EventBus;

/**
 *
 * @fileName: ConcreteSubject
 * @author: zengqf3
 * @date: 2021-4-23 15:06
 * @description: 具体主题（被观察者）
 */
public class ConcreteSubject implements Subject{

    private EventBus eventBus;

    public ConcreteSubject() {
        eventBus = new EventBus();
    }

    /**
     * 触发更新
     */
    public void triggle() {
        System.out.println("被观察者事件发生改变");
        this.eventBus.post("guava 观察者模式");
    }

    @Override
    public void register(Observer observer) {
        this.eventBus.register(observer);
    }

    @Override
    public void unregister(Observer observer) {
        this.eventBus.unregister(observer);
    }
}
